package ModelLayer;
import java.util.ArrayList;

public class Sale
{
	private String id;
    private String regDate;
    private String status;
    private double totalPrice;
    private Customer customer;
    private BusinessCustomer businessCustomer;
    private ArrayList<Partsale> partsale;
    
    public Sale(String id, String regDate, String status)
    {
        this.id = id;
        this.regDate = regDate;
        this.status = status;
        customer = null;
        businessCustomer = null;
        partsale = new ArrayList<Partsale>();
    }
    
    public String getId()
    {
        return id;
    }
    
    public String getRegDate()
    {
        return regDate;
    }
    
    public String getStatus()
    {
        return status;
    }
    
    public double getTotalPrice()
    {
        return totalPrice;
    }
    
    public Customer getCustomer()
    {
        return customer;
    }
    
    public BusinessCustomer getBusinessCustomer()
    {
        return businessCustomer;
    }
    
    public ArrayList<Partsale> getPartsale()
    {
        return partsale;
    }
    
    public void setId(String id)
    {
        this.id = id;
    }
    
    public void setRegDate(String regDate)
    {
        this.regDate = regDate;
    }
    
    public void setStatus(String status)
    {
        this.status = status;
    }
    
    public void setCustomer(Customer customer)
    {
            this.customer = customer;
    }
    
    public void setBusinessCustomer(BusinessCustomer businessCustomer)
    {
            this.businessCustomer = businessCustomer;
    }
    
    public void addPartsale(Partsale partsale)
    {
        this.partsale.add(partsale);
    }
    
    public void calcTotalPrice()
    {
        int i = 0;
        double totalPrice = 0;
        while(i < partsale.size())
        {
        	if(businessCustomer == null)
        	{
	            totalPrice = totalPrice + partsale.get(i).getItem().getPrice() * partsale.get(i).getQuantity();
	            i ++;
        	}
        	else
        	{
        		totalPrice = (totalPrice + partsale.get(i).getItem().getPrice() * partsale.get(i).getQuantity()) * (1 - (businessCustomer.getDiscount() / 100));
        		i++;
        	}
        }
        this.totalPrice = totalPrice;
    }
}
